package admin

import (
	"example/model"
	"fmt"
	"github.com/gin-gonic/gin"
)

func GetList(c *gin.Context) {
	pageSize := c.Query("pageSize")
	pageNum := c.Query("pageNum")
	fmt.Println(pageSize, pageNum)
	res := "暂时没有数据"
	c.JSON(200, gin.H{"data": res})
}

func Register(c *gin.Context) {
	var user model.UserModel
	if err := c.ShouldBind(&user); err != nil {
		c.String(400, "not valid data")
	} else {
		id := user.Save()
		c.JSON(200, gin.H{"message": "success", "data": id, "code": 0})
	}
}

func UserLogin(c *gin.Context) {
	var user model.UserModel
	if e := c.Bind(&user); e != nil {
	}

	u := user.QueryByName()
	if u.Password == user.Password {
		c.SetCookie("cookie", string(u.Account), 7200, "/", "localhost", false, true)
		c.JSON(200, gin.H{"code": 0, "message": "success"})
	} else {
		c.JSON(200, gin.H{"code": -1, "message": "wrong password"})
	}
}
